package otherapi.easyexcel;

import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.Test;
import otherapi.easyexcel.handler.CustomSheetWriteHandler;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 10/8/2022 10:02 AM
 */
public class EasyExcelTest {

    @Test
    public void test() throws IOException {
        String fileName = "TestWrite" + System.currentTimeMillis() + ".xlsx";
        File file = new File(fileName);
        if (!file.exists()) {
            file.createNewFile();
        }
        WriteSheet sheet = new WriteSheet();
        sheet.setSheetNo(1);
        sheet.setSheetName("TABLE班级(TABLE_CLASS)");
        List<TestEntity> list = new ArrayList<>();
        for (int i = 0; i < 50000; i++) {
            TestEntity entity = new TestEntity();
            entity.setClassName("班级" + i);
            entity.setClassNo("CLASS" + i);
            list.add(entity);
        }
        EasyExcelUtils.writeExcel(file,sheet,list);
    }


    @Test
    public void test1() throws IOException {
        String fileName = "TestWrite1" + System.currentTimeMillis() + ".xlsx";
        File file = new File(fileName);
        if (!file.exists()) {
            file.createNewFile();
        }
        // WriteSheet sheet1 = new WriteSheet();
        // sheet1.setSheetNo(1);
        // sheet1.setSheetName("TABLE班级(TABLE_CLASS)");
        // List<TestEntity> list = new ArrayList<>();
        // for (int i = 0; i < 1; i++) {
        //     TestEntity entity = new TestEntity();
        //     entity.setClassName("班级" + i);
        //     entity.setClassNo("CLASS" + i);
        //     list.add(entity);
        // }
        // EasyExcelUtils.writeExcel(file,sheet1,list);

        WriteSheet sheet2 = new WriteSheet();
        sheet2.setSheetNo(2);
        sheet2.setSheetName("TABLE班级(TABLE_CLASS)");
        List<Test1Entity> list2 = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            Test1Entity entity = new Test1Entity();
            entity.setClassNo("CLASS0");
            entity.setName("STUDENT"+i);
            list2.add(entity);
        }
        EasyExcelUtils.writeExcel(file,sheet2,list2);
    }

    @Test
    public void test2() throws IOException {
        String fileName = "TestWrite" + System.currentTimeMillis() + ".xlsx";
        File file = new File(fileName);
        if (!file.exists()) {
            file.createNewFile();
        }
        WriteSheet sheet = new WriteSheet();
        sheet.setSheetNo(1);
        sheet.setSheetName("TABLE班级(TABLE_CLASS)");
        List<WriteHandler> writeHandlerList = new ArrayList<>();
        CustomSheetWriteHandler customSheetWriteHandler = new CustomSheetWriteHandler();
        writeHandlerList.add(customSheetWriteHandler);
        sheet.setCustomWriteHandlerList(writeHandlerList);
        List<TestEntity> list = new ArrayList<>();
        EasyExcelUtils.writeExcel(file,sheet,list);
    }

}
